package com.dz.wx.config;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableConfigurationProperties(WxConfigProperties.class)
public class WxAppConfig extends WebMvcConfigurerAdapter {

	@Autowired
	private WxConfigProperties wxConfigProperties;

	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		File file = new File(wxConfigProperties.getLocalPath());
		if (!file.exists()) {
			file.mkdirs();
		}
		registry.addResourceHandler(wxConfigProperties.getImageHost() + "/**").addResourceLocations(
				"file:" + wxConfigProperties.getLocalPath());
	}
}
